package com.ruoyi.employer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.employer.domain.Transfers;
import lombok.Data;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.employer.domain.PayBankCards;
import com.ruoyi.employer.service.IPayBankCardsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货主银行卡管理Controller
 *
 * @author ysq
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/employer/payBankCards")
public class PayBankCardsController extends BaseController
{
    @Autowired
    private IPayBankCardsService payBankCardsService;


    /**
     * 查询货主银行卡管理列表
     */
    @PreAuthorize("@ss.hasPermi('employer:payBankCards:list')")
    @GetMapping("/list")
    public TableDataInfo list(PayBankCards payBankCards)
    {
        startPage();
        List<PayBankCards> list = payBankCardsService.selectPayBankCardsList(payBankCards);
        return getDataTable(list);
    }

    /**
     * 导出货主银行卡管理列表
     */
    @PreAuthorize("@ss.hasPermi('employer:payBankCards:export')")
    @Log(title = "货主银行卡管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PayBankCards payBankCards)
    {
        List<PayBankCards> list = payBankCardsService.selectPayBankCardsList(payBankCards);
        ExcelUtil<PayBankCards> util = new ExcelUtil<PayBankCards>(PayBankCards.class);
        util.exportExcel(response, list, "货主银行卡管理数据");
    }

    /**
     * 获取货主银行卡管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('employer:payBankCards:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(payBankCardsService.selectPayBankCardsById(id));
    }

    /**
     * 新增货主银行卡管理
     */
    @PreAuthorize("@ss.hasPermi('employer:payBankCards:add')")
    @Log(title = "货主银行卡管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PayBankCards payBankCards)
    {
        return toAjax(payBankCardsService.insertPayBankCards(payBankCards));
    }

    /**
     * 修改货主银行卡管理
     */
    @PreAuthorize("@ss.hasPermi('employer:payBankCards:edit')")
    @Log(title = "货主银行卡管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PayBankCards payBankCards)
    {
        return toAjax(payBankCardsService.updatePayBankCards(payBankCards));
    }

    /**
     * 删除货主银行卡管理
     */
    @PreAuthorize("@ss.hasPermi('employer:payBankCards:remove')")
    @Log(title = "货主银行卡管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(payBankCardsService.deletePayBankCardsByIds(ids));
    }
    /**
     * 获取货主银行卡管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('employer:payBankCards:query')")
    @GetMapping(value = "/cargo/{id}")
    public AjaxResult selectByCargoUserId(@PathVariable("id") Long cargoUserId)
    {
        return success(payBankCardsService.selectByCargoUserId(cargoUserId));
    }
    /*
    * 转账
    * */
    @PreAuthorize("@ss.hasPermi('employer:payBankCards:edit')")
    @Log(title = "货主银行卡管理", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/transfers")
    public AjaxResult transfers(@RequestBody Transfers transfers)
    {
        Double amount = transfers.getAmount();
        return toAjax(payBankCardsService.transfer(transfers.getFromBankCardNumber(),transfers.getToCargoUserId(), amount));
    }
}
